/*
day461 
2020.12.1 
*/
#include<iostream>
#include<vector>
#include<stack>
using namespace std;

struct TreeNode {
   int val;
   TreeNode *left;
   TreeNode *right;
    TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};

class Solution {
	stack<TreeNode *> sta;
	TreeNode *p=nullptr;
	
public:
    int kthLargest(TreeNode* root, int k) {
		p=root;
		for(int i=0;i<k-1;++i) next();
		return next();
    }
    
    int next()
    {
    	int res;
    	
    	while(p)
    	{
    		sta.push(p);
    		p=p->right;
		}
			
		p=sta.top();
		sta.pop();
		res=p->val;
		p=p->left;
		
		return res;
	}
};

int main()
{
	return 0;
}
